package com.example.doctorstation.Handler;

import com.example.doctorstation.Config.MyResponse;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Victoria-Al
 * @date 2021-05-06
 * 描述：用户登录统一异常处理
 **/
@RestControllerAdvice
public class UserExceptionHandler {
    private static final String UNAUTHORIZED = "没有权限";

    @ExceptionHandler(UnauthorizedException.class)
    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    public MyResponse UnAuthorizedExceptionHandler(UnauthorizedException e) {
        return MyResponse.error(UNAUTHORIZED);
    }
}
